<template>
  <a-modal
    :title="title"
    :width="600"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
    wrapClassName="ant-modal-cust-warp"
    style="top: 5%; height: 90%; overflow-y: hidden"
  >
    <a-spin :spinning="confirmLoading">
      <div class="reportList">
        <div class="list-wrap">
          <div class="li" v-for="(item, index) in evenList" :key="index">
            <a :href="'#item-' + item.id" @click="useList(item)">{{ item.content }}</a>
            <span>{{item.createTime}}</span>
          </div>
        </div>
      </div>
    </a-spin>
  </a-modal>
</template>

<script>
import { addRole, editRole, duplicateCheck } from '@/api/api'
export default {
  name: 'RoleModal',
  data() {
    return {
      // listData:[
      //   {content:' 识和能力，并帮助学生提高汉语口头表达能力。我的第一个要求是需要读、写作等方面的知识和能力，并帮助学生提高汉语口头表达能力。我的第一个要求是需要有人帮我写一篇作文。'},
      //   {content:' 读、写作等方面的知识和能力，并帮助学生提高汉语口头表达能力。我的第一个要求是需要有人帮我写一篇作文。'},
      // ],
      disableSubmit: false,
      newMessage: '',
      title: '操作',
      visible: false,
      roleDisabled: false,
      model: {},
      confirmLoading: false,
      arrow_r: '111111111111',
    }
  },
  props: {
    listData: {
      type: Array,
      default: [],
    },
  },
  computed: {
    evenList: function () {
      return this.listData.filter(function (item) {
        return item.role === 'user'
      })
    },
  },
  mounted() {
    //
    console.log('listData', this.listData)
  },
  methods: {
    //监听滚动条距离
    orderScroll(e) {
      let scrollHeight = e.target.scrollHeight
      let clientHeight = e.target.clientHeight
      let scrollTop = e.target.scrollTop
      // console.log('scrollHeight',e,scrollHeight,clientHeight,scrollTop)
      if (scrollHeight - (scrollTop + clientHeight) <= 1) {
        this.isRead = true //  这是一个disabled的显示，自己定义的
        this.confirmText = '同意' // 更改一个内容文字
      }
    },
    //使用聊天弹框语言
    useList(id) {
      this.visible = false
      this.$emit('ok', id)
    },
    //查询
    sendMessage() {
      if (this.newMessage.trim() !== '') {
      }
    },
    // 点击展开折叠菜单事件
    showToggle(item, ind) {
      this.menuList.forEach((i) => {
        // 判断如果数据中的menuList[i]的show属性不等于当前数据的isSubShow属性那么menuList[i]等于false
        if (i.isSubShow !== this.menuList[ind].isSubShow) {
          i.isSubShow = false
        }
      })
      item.isSubShow = !item.isSubShow
    },
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
      //编辑页面禁止修改角色编码
      if (this.model.id) {
        this.roleDisabled = true
      } else {
        this.roleDisabled = false
      }
    },
    close() {
      // this.$refs.form.clearValidate()
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let obj
          if (!this.model.id) {
            obj = addRole(this.model)
          } else {
            obj = editRole(this.model)
          }
          obj
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>

<style lang="less">
.reportList {
  float: left;
  width: 100%;
  padding: 20px;
  height: 100%;
  .list-wrap {
    height: 400px;
    overflow: hidden auto;
    .li {
      cursor: pointer;
      padding: 12px 20px;
      margin-bottom: 2px;
      border-radius: 8px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      display: flex;
      justify-content: space-between;
      a {
        color: black;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      span{
      }
    }
    .li:hover {
      color: #7a46fc;
      background: #f2edff;
    }
  }
}
</style>